/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.namabank.util;

import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author Nguyen Tran Hien
 */
public class HttpUtil {
    public static String getFullHTTPPath(HttpServletRequest request, String relativePath) {
        if(relativePath != null && relativePath.startsWith("http"))
            return relativePath;
        String res = request.getScheme() + "://" + request.getServerName();
        if (request.getLocalPort() != 80) {
            res += ":" + request.getLocalPort();
        }
        res += request.getContextPath();
        if (relativePath != null && relativePath.length() > 0) {
            if (!relativePath.startsWith("/")) {
                res += "/";
            }
            res += relativePath;
        }
        return res;
    }
}
